#include "ui_param_widget_conventional.h"
#include "mvc/view/param_widget_conventional.h"
#include "mvc/view/airfoil_dialog.h"
#include "mvc/view/configuration_dialog.h"
#include "mvc/model/aircrafts/aircraft_rcurves.h"
#include "mvc/model/aircrafts/aircraft_parameters.h"

#include "common/settings.h"
#include "common/modules.h"
#include "common/log/QsLog.h"
#include <QMessageBox>

Param_widget_conventional::Param_widget_conventional(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Param_widget_conventional)
{
    ad = new Airfoil_dialog(this);
    af_reference_curve = new Airfoils_curve_map();
    ui->setupUi(this);
    closed = false;
    load_images();
    set_reg_exp();
    set_signal_buttons();
    charge_test();
}

Param_widget_conventional::~Param_widget_conventional()
{
    delete ui;
    closed = true;
}

Airfoil_dialog *Param_widget_conventional::get_airfoil_dialog()
{
    return ad;
}
/**
 * @brief Param_widget_conventional::retranslateUi
 * Set text in the widget
 */
void Param_widget_conventional::retranslateUi(){
    ui->retranslateUi(this);
}


/**
 * @brief Param_widget_uav::getClosed
 * @return value of atribute 'closed'
 */
bool Param_widget_conventional::getClosed(){
    return closed;
}

/**
 * Set the action of each button.
 */
void Param_widget_conventional::set_signal_buttons()
{
    connect(ui->front_view_wing_button, SIGNAL(clicked()), this, SLOT(front_view_wing_clicked()));
    connect(ui->top_view_wing_button, SIGNAL(clicked()), this, SLOT(top_view_wing_clicked()));
    connect(ui->ok_button, SIGNAL(clicked()), this, SLOT(control_parameteres()));
    connect(ui->fwing_airfoil_button, SIGNAL(clicked()), this, SLOT(load_fwing_button()));
    connect(ui->bwing_airfoil_button, SIGNAL(clicked()), this, SLOT(load_bwing_button()));
    connect(ui->wingtip_forward_airfoil_button, SIGNAL(clicked()), this, SLOT(load_forwardWingtip_button()));
    connect(ui->wingtip_backwing_airfoil_button, SIGNAL(clicked()), this, SLOT(load_backwardWingtip_button()));
    connect(ui->joinedWing_airfoil_button, SIGNAL(clicked()), this, SLOT(load_joinedWing_button()));
}


/**
*  Action when bwing_button is pressed.
*/
void Param_widget_conventional::load_bwing_button()
{
    //std::cout << "load bwing button" << std::endl;
    show_airfoil_dialog();
    last_button_pressed = BWING;
}
/**
*  Action when fwing_button is pressed.
*/
void Param_widget_conventional::load_fwing_button()
{
    //std::cout << "load fwing button" << std::endl;
    show_airfoil_dialog();
    last_button_pressed = FWING;
}

/**
*  Action when lwing_button is pressed.
*/
void Param_widget_conventional::load_lwing_button()
{
    //std::cout << "load lwing button" << std::endl;
    show_airfoil_dialog();
    last_button_pressed = LWING;
}

/**
*  Action when wingtip_button is pressed.
*/
void Param_widget_conventional::load_forwardWingtip_button()
{
    //std::cout << "load wingtip button" << std::endl;
    show_airfoil_dialog();
    last_button_pressed = WINGTIP;
}

/**
*  Action when backward wingtip_button is pressed.
*/
void Param_widget_conventional::load_backwardWingtip_button()
{
    show_airfoil_dialog();
    last_button_pressed = BWINGTIP;
}

/**
*  Action when Outer wing airfoil button is pressed.
*/
void Param_widget_conventional::load_joinedWing_button()
{
    //std::cout << "load wingtip button" << std::endl;
    show_airfoil_dialog();
    last_button_pressed = OWING;
}

/**
*  Set the file name of bwing parameter in the file edit.
*/
void Param_widget_conventional::set_bwing(QString file_name)
{
    ui->bwing_edit->setText(file_name);
}

/**
*  Set the file name of fwing parameter in the file edit.
*/
void Param_widget_conventional::set_fwing(QString file_name)
{
    ui->fwing_edit->setText(file_name);
}

/**
*  Set the file name of wingtip parameter in the file edit.
*/
void Param_widget_conventional::set_forward_wingtip(QString file_name)
{
    ui->wingtip_forward_edit->setText(file_name);
}

/**
*  Set the file name of Outer wing parameter in the file edit.
*/
void Param_widget_conventional::set_joinedWing(QString file_name)
{
    ui->joined_wing_edit->setText(file_name);
}

/**
 * Set a regular expression for each line edit.
 */
void Param_widget_conventional::set_reg_exp()
{
    QRegExp regExp("(0|[1-9][0-9]*)\\.[0-9]+(\\-(0|[1-9][0-9]*)\\.[0-9]+\\,(0|[1-9][0-9]*)\\.[0-9]+)?");
    //         |       double           | - |     double             |, |         double       |
    QRegExp regExpInteger("([1-9][0-9]*)(-([1-9][0-9]*),([1-9][0-9]*))?");
    //fuselage
    ui->l->setValidator(new QRegExpValidator(regExp,this));
    ui->d->setValidator(new QRegExpValidator(regExp,this));
    ui->xfa->setValidator(new QRegExpValidator(regExp,this));
    ui->npf->setValidator(new QRegExpValidator(regExpInteger, this)) ;
    ui->xnfs->setValidator(new QRegExpValidator(regExp,this)) ;
    ui->dt->setValidator(new QRegExpValidator(regExp,this)) ;
    ui->lt->setValidator(new QRegExpValidator(regExp,this)) ;
    //wing
    ui->ct->setValidator(new QRegExpValidator(regExp,this)) ;
    ui->cj->setValidator(new QRegExpValidator(regExp,this)) ;
    ui->crf->setValidator(new QRegExpValidator(regExp,this)) ;
    ui->cra->setValidator(new QRegExpValidator(regExp,this)) ;
    ui->npc_forward->setValidator(new QRegExpValidator(regExpInteger, this)) ;
    ui->sob->setValidator(new QRegExpValidator(regExp,this)) ;

    ui->d_ob->setValidator(new QRegExpValidator(regExp,this)) ;

    ui->l_ob->setValidator(new QRegExpValidator(regExp,this)) ;

    ui->arf_forward->setValidator(new QRegExpValidator(regExp,this)) ;
    ui->arf_backwing->setValidator(new QRegExpValidator(regExp,this)) ;
    ui->ara->setValidator(new QRegExpValidator(regExp,this)) ;
    ui->aj->setValidator(new QRegExpValidator(regExp,this)) ;

    ui->d_ib_backwing->setValidator(new QRegExpValidator(regExp,this)) ;
    ui->d_ib_forward->setValidator(new QRegExpValidator(regExp,this)) ;
    ui->l_ib_backwing->setValidator(new QRegExpValidator(regExp,this)) ;
    ui->l_ib_forward->setValidator(new QRegExpValidator(regExp,this)) ;
    ui->npc_backwing->setValidator(new QRegExpValidator(regExpInteger, this)) ;
    ui->sib_backwing->setValidator(new QRegExpValidator(regExp,this)) ;
    ui->sib_forward->setValidator(new QRegExpValidator(regExp,this)) ;
    ui->cz->setValidator(new QRegExpValidator(regExp,this)) ;
    //empennage
    ui->zfa->setValidator(new QRegExpValidator(regExp,this)) ;
    ui->npev->setValidator(new QRegExpValidator(regExpInteger, this)) ;
    //snout
    ui->ln->setValidator(new QRegExpValidator(regExp,this)) ;
    ui->dn->setValidator(new QRegExpValidator(regExp,this)) ;
    ui->npm->setValidator(new QRegExpValidator(regExpInteger, this)) ;
}

/**
 * @brief Param_widget_conventional::get_widget_parameters
 * Obtains the values of the widget and emmit this
 */
void Param_widget_conventional::get_widget_parameters()
{

    ParametersWidget *pw = new ParametersWidget();

    QMap<QString, QString> fuselageParameters;

    fuselageParameters.insert(fuselage_l, ui->l->text());
    fuselageParameters.insert(fuselage_d, ui->d->text());
    fuselageParameters.insert(fuselage_npf, ui->npf->text());
    fuselageParameters.insert(fuselage_xnfs, ui->xnfs->text());
    fuselageParameters.insert(fuselage_dt, ui->dt->text());
    fuselageParameters.insert(fuselage_lt, ui->lt->text());
    fuselageParameters.insert(fuselage_ln, ui->ln->text());
    fuselageParameters.insert(fuselage_dn, ui->dn->text());
    fuselageParameters.insert(fuselage_npm, ui->npm->text());
    pw->insert(s_fuselage, fuselageParameters);

    QMap<QString, QString> wing;
    wing.insert(wings_ct, ui->ct->text());
    wing.insert(wings_cj, ui->cj->text());
    wing.insert(wings_crf, ui->crf->text());
    wing.insert(wings_sob, ui->sob->text());
    wing.insert(wings_sib, ui->sib_forward->text());
    wing.insert(wings_dob, ui->d_ob->text());
    wing.insert(wings_dib, ui->d_ib_forward->text());
    wing.insert(wings_lob, ui->l_ob->text());
    wing.insert(wings_lib, ui->l_ib_forward->text());
    wing.insert(wings_arf, ui->arf_forward->text());
    wing.insert(wings_aj, ui->aj->text());
    wing.insert(wings_at, ui->at->text());
    wing.insert(wings_npc, ui->npc_forward->text());
    pw->insert(s_wings, wing);

    QMap<QString, QString> htail;
    htail.insert(htail_xfa, ui->xfa->text());
    htail.insert(htail_cra, ui->cra->text());
    htail.insert(htail_cz, ui->cz->text());
    htail.insert(htail_sib, ui->sib_backwing->text());
    htail.insert(htail_dib, ui->d_ib_backwing->text());
    htail.insert(htail_lib, ui->l_ib_backwing->text());
    htail.insert(htail_ara, ui->ara->text());
    htail.insert(htail_arf, ui->arf_backwing->text());
    htail.insert(htail_npc, ui->npc_backwing->text());
    pw->insert(s_horizontal_tail, htail);

    QMap<QString, QString> vtail;
    vtail.insert(vtail_zfa, ui->zfa->text());
    vtail.insert(vtail_npev, ui->npev->text());
    pw->insert(s_vertical_tail, vtail);

    //airfoil
    QMap<QString, QString> airfoils;
    airfoils.insert(wings_root, ui->fwing_edit->text());
    airfoils.insert(wings_join, ui->joined_wing_edit->text());
    airfoils.insert(wings_wingtip, ui->wingtip_forward_edit->text());
    airfoils.insert(htail_root, ui->bwing_edit->text());
    airfoils.insert(htail_wingtip, ui->wingtip_backwing_edit->text());
    pw->insert("airfoils",airfoils);

    emit s_load_parameters(pw, af_reference_curve, get_module_value(conventional_w_module));
}
/**
 * @brief Param_widget_conventional::control_param
 * controls every required field of the widget.
 * @return true, if all field are correctly completed.
 *         false, otherwise.
 */
bool Param_widget_conventional::control_param()
{
    if(ui->l->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'L' field is empty"));
        return false;
    }

    if(ui->lt->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'Lt' field is empty"));
        return false;
    }

    if(ui->d->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'd' field is empty"));
        return false;
    }

    if(ui->xfa->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'xfa' field is empty"));
        return false;
    }

    if(ui->npf->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'npf' field is empty"));
        return false;
    }

    if(ui->xnfs->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'xnfs' field is empty"));
        return false;
    }
    if(ui->dt->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'dt' field is empty"));
        return false;
    }

    if(ui->lt->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'lt' field is empty"));
        return false;
    }

    if(ui->ct->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'ct' field is empty"));
        return false;
    }

    if(ui->cj->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'cj' field is empty"));
        return false;
    }

    if(ui->crf->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'crf' field is empty"));
        return false;
    }

    if(ui->cra->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'cra' field is empty"));
        return false;
    }

    if(ui->npc_forward->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'npc' field in forward wing is empty"));
        return false;
    }

    if(ui->npc_backwing->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'npc' field in backward wing is empty"));
        return false;
    }

    if(ui->sob->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'Sob' field is empty"));
        return false;
    }

    if(ui->sib_forward->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'Sib' field is empty"));
        return false;
    }

    if(ui->d_ob->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'δob' field is empty"));
        return false;
    }

    if(ui->d_ib_forward->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'δib' field is empty"));
        return false;
    }

    if(ui->l_ob->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'Λob' field is empty"));
        return false;
    }

    if(ui->l_ib_forward->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'Λib' field is empty"));
        return false;
    }

    if(ui->arf_forward->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'arf' field in forward wing is empty"));
        return false;
    }

    if(ui->arf_backwing->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'arf' field in backward wing is empty"));
        return false;
    }

    if(ui->ara->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'ara' field is empty"));
        return false;
    }

    if(ui->aj->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'aj' field is empty"));
        return false;
    }

    if(ui->at->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'at' field is empty"));
        return false;
    }

    if(ui->bwing_edit->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'HTail root' field is empty"));
        return false;
    }
    else
    {
        if(!valid_file(ui->bwing_edit->text()))
        {
            QMessageBox::warning(this, tr("Warning"), tr("'HTail root'. File not valid"));
            return false;
        }
    }

    if(ui->fwing_edit->text()=="")
    {
        QMessageBox::warning(this, tr("Warning"), tr("The 'Wing' field is empty"));
        return false;
    }
    else
    {
        if(!valid_file(ui->fwing_edit->text()))
        {
            QMessageBox::warning(this, tr("Warning"), tr("'Wing'. File not valid"));
            return false;
        }
    }


    if(ui->wingtip_forward_edit->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'Wingtip' field is empty"));
        return false;
    }
    else
    {
        if(!valid_file(ui->wingtip_forward_edit->text()))
        {
            QMessageBox::warning(this, tr("Warning"), tr("'Wingtip'. File not valid"));
            return false;
        }
    }

    if(ui->joined_wing_edit->text()=="")
    {
        QMessageBox::warning(this, tr("Warning"), tr("The 'Outer wing' field is empty"));
        return false;
    }
    else
    {
        if(!valid_file(ui->joined_wing_edit->text()))
        {
            QMessageBox::warning(this, tr("Warning"), tr("'Outer wing'. File not valid"));
            return false;
        }
    }

    if(ui->zfa->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'zfa' field is empty"));
        return false;
    }

    if(ui->npev->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'npev' field is empty"));
        return false;
    }

    if(ui->ln->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'Ln' field is empty"));
        return false;
    }

    if(ui->dn->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'dn' field is empty"));
        return false;
    }
    if(ui->npm->text()==""){
        QMessageBox::warning(this, tr("Warning"), tr("The 'npm' field is empty"));
        return false;
    }
    return true;
}

/**
 * @brief Param_widget_conventional::valid_file
 * @param nameFile: name of a file to control.
 * @return true, if the namefile already exists
 *         false, otherwise.
 */
bool Param_widget_conventional::valid_file(QString nameFile)
{
    QString path = airfoils_directory();
    path.append("/");
    path.append(nameFile);

    QFile file(path);
    if (!file.open(QIODevice::ReadOnly))
    {
        std::cerr << "Cannot open the file (Param widget::invalide file): " << path.toStdString() <<std::endl;
        file.close();
        return false;
    }

    file.close();

    return true;
}


/**
  * Load the images of each tab.
  */
void Param_widget_conventional::load_images()
{
    //Fuselage tab
    QImage image_fuselage(":images/convencional-fuselaje.png");
    ui->uav_fuselage_image->setPixmap(QPixmap::fromImage(image_fuselage));
    ui->uav_fuselage_image->setScaledContents(true);

    QImage image_parameters_lateral_view_fuselage(":images/conventional_lateral_view_fuselage.png");
    ui->uav_fuselage_lateral_view_image->setPixmap(QPixmap::fromImage(image_parameters_lateral_view_fuselage));
    ui->uav_fuselage_lateral_view_image->setScaledContents(true);

    //Wing tab
    QImage image_wing(":images/convencional-alas.png");
    ui->uav_wing_image->setPixmap(QPixmap::fromImage(image_wing));
    ui->uav_wing_image->setScaledContents(true);

    QImage image_parameters_top_view_wing(":images/conventional_top_view_wing.png");
    ui->uav_wing_top_view_image->setPixmap(QPixmap::fromImage(image_parameters_top_view_wing));
    ui->uav_wing_top_view_image->setScaledContents(true);

    //Tail tab
    QImage image_tail(":images/convencional-empenaje.png");
    ui->uav_tail_image->setPixmap(QPixmap::fromImage(image_tail));
    ui->uav_tail_image->setScaledContents(true);

    QImage image_parameters_front_view_tail(":images/conventional_front_view_tail.png");
    ui->uav_tail_front_view_image->setPixmap(QPixmap::fromImage(image_parameters_front_view_tail));
    ui->uav_tail_front_view_image->setScaledContents(true);

    //Horizontal tail tab
    QImage image_horizontal_tail(":images/convencional-horizontal-tail.png");
    ui->uav_hotizontal_tail_image->setPixmap(QPixmap::fromImage(image_horizontal_tail));
    ui->uav_hotizontal_tail_image->setScaledContents(true);

    //QImage image_parameters_front_view_tail(":images/UAV_front_view_tail.png");
    //ui->uav_tail_front_view_image->setPixmap(QPixmap::fromImage(image_parameters_front_view_tail));
    //ui->uav_tail_front_view_image->setScaledContents(true);



    //Nose tab
    QImage image_nose(":images/convencional-morro.png");
    ui->uav_nose_image->setPixmap(QPixmap::fromImage(image_nose));
    ui->uav_nose_image->setScaledContents(true);

    QImage image_parameters_lateral_view_nose(":images/conventional_lateral_view_nose.png");
    ui->uav_nose_lateral_view_image->setPixmap(QPixmap::fromImage(image_parameters_lateral_view_nose));
    ui->uav_nose_lateral_view_image->setScaledContents(true);
}




/**
* Actions when top_view button in wing tab is clicked.
*/
void Param_widget_conventional:: top_view_wing_clicked()
{
    ui->uav_wing_front_view_image->clear();
//            ->setPixmap(NULL);
    QImage image_parameters_wing(":images/conventional_top_view_wing.png");
    ui->uav_wing_top_view_image->setPixmap(QPixmap::fromImage(image_parameters_wing));
    ui->uav_wing_top_view_image->setScaledContents(true);
}

/**
* Actions when front_view button in wing tab is clicked.
*/
void Param_widget_conventional:: front_view_wing_clicked()
{
    ui->uav_wing_top_view_image->clear();
//            ->setPixmap(NULL);
    QImage image_parameters_wing(":images/conventional_front_view_wing.png");
    ui->uav_wing_front_view_image->setPixmap(QPixmap::fromImage(image_parameters_wing));
    ui->uav_wing_front_view_image->setScaledContents(true);
}

/**
*  Open a new window 'Airfoil_dialog'
*/
void Param_widget_conventional::show_airfoil_dialog()
{

    ad->show();
}

/**
  * Open a new window 'Configuration_dialog'
  */
void Param_widget_conventional::control_parameteres()
{
    if(control_param())
    {
        this->close();
        closed = true;
        get_widget_parameters();
    }
}

/**
 * @brief Param_widget_conventional::charge_test
 * Set some values to the field to test the widget
 */
void Param_widget_conventional::charge_test()
{
    ui->l->setText("40.0");
    ui->d->setText("4.0");
    ui->xfa->setText("30.0");
    ui->npf->setText("5");
    ui->xnfs->setText("9.0");
    ui->dt->setText("0.5");
    ui->ara->setText("0");
    ui->lt->setText("2.5");
    ui->ct->setText("2.5");
    ui->cj->setText("2.5");
    ui->crf->setText("2.5");
    ui->cra->setText("2.5");
    ui->npc_forward->setText("5");
    ui->sob->setText("6.25");
    ui->sib_forward->setText("26.00");
    ui->d_ob->setText("20.0");
    ui->d_ib_forward->setText("15.0");
    ui->l_ob->setText("30.0");
    ui->l_ib_forward->setText("30.0");
    ui->arf_forward->setText("0");
    ui->cz->setText("2.5");
    ui->sib_backwing->setText("6.00");
    ui->d_ib_backwing->setText("15.00");
    ui->l_ib_backwing->setText("30.00");
    ui->arf_backwing->setText("0");
    ui->npc_backwing->setText("8");
    ui->aj->setText("0");
    ui->at->setText("0");
    ui->zfa->setText("3.00");
    ui->npev->setText("7");
    ui->ln->setText("4.0");
    ui->dn->setText("0.7");
    ui->npm->setText("3");
    ui->ct->setText("2.5");

    ui->fwing_edit->setText("ag04.dat");
    QString path_one(airfoils_directory());
    path_one.append("ag04.dat");
    ad->calc_reference_curve(path_one);
    af_reference_curve->insert(wings_root, ad->get_reference_curve());

    ui->bwing_edit->setText("ag04.dat");
    QString path_two(airfoils_directory());
    path_two.append("ag04.dat");
    ad->calc_reference_curve(path_two);
    af_reference_curve->insert(htail_root, ad->get_reference_curve());

    ui->wingtip_forward_edit->setText("ag04.dat");
    QString path_four(airfoils_directory());
    path_four.append("ag04.dat");
    ad->calc_reference_curve(path_four);
    af_reference_curve->insert(wings_wingtip, ad->get_reference_curve());

//    QString path_five(airfoils_directory());
//    path_five.append("ag04.dat");
//    ad->calc_reference_curve(path_five);
//    af_reference_curve->insert("vtail_root",ad->get_reference_curve());

    ui->wingtip_backwing_edit->setText("ag04.dat");
    QString path_six(airfoils_directory());
    path_six.append("ag04.dat");
    ad->calc_reference_curve(path_six);
    af_reference_curve->insert(htail_wingtip, ad->get_reference_curve());

    ui->joined_wing_edit->setText("ag04.dat");
    QString path_fseven(airfoils_directory());
    path_fseven.append("ag04.dat");
    ad->calc_reference_curve(path_fseven);
    af_reference_curve->insert(wings_join, ad->get_reference_curve());
}


/**
*  Load the values selected of airfoil window.
*/
void Param_widget_conventional::load_airfoil_value(QVector<Point *> point_list, QString file_name, int button_pressed)
{
    QLOG_INFO() << "LOAD AIRFOIL_VALUE IN CONVENTIONAL";

    switch (button_pressed)
    {
    case BWING :    ui->bwing_edit->setText(file_name);
        af_reference_curve->insert(htail_root, point_list);
        break;
    case FWING :    ui->fwing_edit->setText(file_name);
        af_reference_curve->insert(wings_root, point_list);
        break;

    case BWINGTIP :    ui->wingtip_backwing_edit->setText(file_name);
        af_reference_curve->insert(htail_wingtip, point_list);
        break;

    case WINGTIP :  ui->wingtip_forward_edit->setText(file_name);
        af_reference_curve->insert(wings_wingtip, point_list);
        break;

    case OWING :  ui->joined_wing_edit->setText(file_name);
        af_reference_curve->insert(wings_join, point_list);
        break;
    }
}

